package me.zk.practice1.s;

import java.util.HashMap;

/**
 * @author zhangkai
 * @date 2023/7/31 13:05
 */
public class LS3 {
    public static int lengthOfLongestSubstring(String s) {
        if (s.length() == 0) {
            return 0;
        }
        int maxLen = 0;
        HashMap<Character,Integer> map = new HashMap<>();
        int l = 0;
        for (int i = 0; i < s.length(); i++) {
            if (map.containsKey(s.charAt(i))) {
             l = Math.max(l,map.get(s.charAt(i))+1);
            }
            map.put(s.charAt(i),i);
            maxLen = Math.max(maxLen,i-l+1);

        }
        
        return maxLen;

    }

    public static void main(String[] args) {
        lengthOfLongestSubstring("abcabcbb");
    }
}
